package com.example.meterialproject.exts

import android.annotation.SuppressLint
import android.content.Context
import android.view.View
import android.widget.Toast
import com.google.android.material.snackbar.Snackbar

/**
 *
 * @ClassName: ContentExt
 * @Author: android 超级兵
 * @CreateDate: 1/7/22$ 5:27 PM$
 * TODO
 */

/**
 * 作者:android 超级兵
 * TODO 获取屏幕宽度
 */
val Context.screenWidth
    get() = resources.displayMetrics.widthPixels

/**
 * 作者:android 超级兵
 * TODO  获取屏幕高度
 */
val Context.screenHeight
    get() = resources.displayMetrics.heightPixels

// 屏幕的三分之二
val Context.screenHeight32
    get() = resources.displayMetrics.heightPixels * 2 / 3

val Context.TAG_CURRENT_THREAD
    get() = "szj_${this.javaClass.simpleName} thread:[${Thread.currentThread().name}]"

val Context.TAG
    get() = "szj_${this.javaClass.simpleName}"

val View.TAG_CURRENT_THREAD
    get() = "szj_${this.javaClass.simpleName} thread:[${Thread.currentThread().name}]"

val View.TAG
    get() = "szj_${this.javaClass.simpleName}"




//TODO show toast
@SuppressLint("ShowToast")
infix fun <T> T.toast(context: Context) {
    Toast.makeText(context, this.toString(), Toast.LENGTH_SHORT).show()
}

infix fun <T> Context.toast(any: T) {
    Toast.makeText(this, any.toString(), Toast.LENGTH_SHORT).show()
}

// TODO show Snack
infix fun <T : CharSequence> T.showSnack(view: View) {
    Snackbar.make(view, this, Snackbar.LENGTH_SHORT).show()
}

infix fun <T> View.showSnack(any: T?) {
    any?.toString()?.also {
        if (it.isNotEmpty()) {
            Snackbar.make(this, it, Snackbar.LENGTH_SHORT).show()
        }
    }
}


